define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  const ids = Fast.api.query('ids');
  
	const controller = {
		index() {
			Table.api.init({
				extend: {
					index_url: 'business/privatesea/index',
					add_url: 'business/privatesea/add',
					edit_url: 'business/privatesea/edit',
					del_url: 'business/privatesea/del',
					table: 'business',
				},
			});

			//绑定事件
			$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
				var panel = $($(this).attr('href'));
				if (panel.length > 0) {
					controller.table[panel.attr('id')].call(this);
					$(this).on('click', function (e) {
						$($(this).attr('href')).find('.btn-refresh').trigger('click');
					});
				}
				//移除绑定的事件
				$(this).unbind('shown.bs.tab');
			});

			//必须默认触发shown.bs.tab事件
			$('ul.nav-tabs li.active a[data-toggle="tab"]').trigger('shown.bs.tab');
		},
		table: {
			info() {},
			visit() {
				const table2 = $('#table2');

				table2.bootstrapTable({
					url: 'business/privateseainfo/visit?ids=' + ids,
					extend: {
						add_url: 'business/privateseainfo/add?ids=' + ids,
						edit_url: 'business/privateseainfo/edit',
						del_url: 'business/privateseainfo/del',
						table: 'business_visit',
					},
					toolbar: '#toolbar2',
					sortName: 'visit.createtime',
          search: false,
          showExport: false,
					columns: [
						[
							{ checkbox: true },
							{ field: 'id', title: __('Id'), sortable: true },
							{ field: 'business.nickname', title: __('Bnickname'), operate: 'LIKE' },
							{ field: 'content', title: __('Vcontent'), operate: 'LIKE' },
							{ field: 'admin.nickname', title: __('Dnickname'), sortable: false, searchable: false },
							{
								field: 'createtime',
								title: __('VisitCreateTime'),
								formatter: Table.api.formatter.datetime,
								operate: 'RANGE',
								addclass: 'datetimerange',
							},
							{
								field: 'operate',
								title: __('Operate'),
								table: table2,
								events: Table.api.events.operate,
								formatter: Table.api.formatter.operate,
							},
						],
					],
				});

				Table.api.bindevent(table2);
			},
			// 申请记录
			receive() {
				const table3 = $('#table3');

				table3.bootstrapTable({
					url: 'business/privateseainfo/receive?ids=' + ids,
					showExport: false,
					extends: {
						table: 'business_receive',
					},
					toolbar: '#toolbar3',
					columns: [
						{ field: 'id', title: __('Id') },
						{ field: 'business.nickname', title: __('Bnickname') },
						{ field: 'admin.username', title: __('Dnickname') },
						{ field: 'status_text', title: __('VstatusText') },
						{ field: 'applytime', title: __('Rapplytime'), formatter: Table.api.formatter.datetime },
					],
				});

				Table.api.bindevent(table3);
			},
		},
		add() {
			controller.api.bindevent();
		},
		edit() {
			controller.api.bindevent();
		},
		del() {
			controller.api.bindevent();
		},
		api: {
			// JS模块化的全局方法
			bindevent: function () {
				Form.api.bindevent($('form[role=form]'));
			},
		},
	};

	return controller;
});
